package com.zyf.workflow.test.work.firmware;

import com.zyf.workflow.node.Node;
import com.zyf.workflow.node.WorkNode;
import com.zyf.workflow.test.work.firmware.bean.FirmwareBean;
import com.zyf.workflow.test.work.firmware.worker.FirmwareUpgradeWorker;
import com.zyf.workflow.work.AbstractWork;
import com.zyf.workflow.work.bean.WorkTypeEnum;
import com.zyf.workflow.worker.Worker;

import java.util.ArrayList;
import java.util.List;

public class CheckBandTypeWork<T> extends AbstractWork<FirmwareBean> {

    public CheckBandTypeWork(FirmwareBean firmwareBean, String workName) {
        super(firmwareBean, workName);
    }


    private Node<String> getCheckBandNode(FirmwareBean firmwareBean) {

        FirmwareUpgradeWorker firmwareUpgradeWorker = new FirmwareUpgradeWorker();
        Worker<FirmwareBean, String, String> worker = firmwareUpgradeWorker::checkBandType;

        return new WorkNode.Builder<FirmwareBean, String>()
                .withWorker(worker)
                .withNodeId(1)
                .withData(firmwareBean)
                .withName(getWorkName() + "1")
                .setCallBack((data, param) -> {
                    System.out.println("check band type Finish, callback called");
                    System.out.println(".....");
                })
                .create();

    }

    @Override
    public List<Node<?>> initNodes(FirmwareBean data) {
        List<Node<?>> nodes = new ArrayList<>();
        Node<String> checkResourceNode = getCheckBandNode(data);
        nodes.add(checkResourceNode);
        return nodes;
    }

    @Override
    public WorkTypeEnum getWorkType() {
        return WorkTypeEnum.DECISION;
    }
}
